<?php 
	require_once ('checks.php');
	if (isset($_GET['article_name']))	{
		require_once ('Database.php');
		require_once ('Articles.php'); 
		$db= new DB();
		if (isset($_POST['go'])) {
			$article= new Article($_POST['article_name'],$_POST['article']);
			$article->setId($_SESSION['id']);	
			$db->updateArticles($article); 
			$db= new  DB();	echo "Article was successfully edited";
		} else {
			$article = $db->extractArticle($_GET['article_name']);
			$_SESSION['id']=$article->getId();
		}

	} else {
		echo " Something Wrong Happened - please go to homepage!";
		die();
	}
?>
	
		<form method="post" action="?page=edit_article&article_name=<?php echo $_GET['article_name']; ?>">
			<table>
			
			<tr>
					<td>
						<label for="article_name">Article Name : </label>
					</td>
					<td colspan="2">	
						<input type="text" name="article_name" id="article_name" value="<?php echo $article->getName()?>">
						
					</td>
				</tr>
				<tr>
					<td style="vertical-align:top;">
						<label for="article" >Article : </label>
					</td>
					<td colspan="2">	
						<textarea name="article" id="article" cols="70" rows="20" >
							<?php 
 								echo $article->getText();
							?>
						</textarea>
					</td>
				</tr>

				<tr>
					<td>
						
					</td>
					<td ><input type="submit" value="Save" name="go">
						<input type="button" value="Home"  onclick="location.href='?page=admin_index'">
					</td>				
				</tr>			
			</table>
		</form>

